package com.atguigu.t_juc_help_class;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

class MyCount{
    int i = 6;
    public synchronized void subCount(){
        i--;
        System.out.println("倒计时"+i);
    }
}

public class MyCurrentDownLatch {
    public static void main(String[] args) throws InterruptedException {
        MyCount myCount = new MyCount();

        // 新建一个countDownLatch 并且传入值为6
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(()->{

                myCount.subCount();
                // 逐次减一 直至减完
                countDownLatch.countDown();

            }).start();
        }
        // 当计数变为0之后放行
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"发射成功！");
    }
}
